package com.xiguthings.waka.service.user.impl;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.xiguthings.waka.dao.DataBaseStatus;
import com.xiguthings.waka.dao.mapper.UserMapper;
import com.xiguthings.waka.po.User;
import com.xiguthings.waka.po.UserExample;
import com.xiguthings.waka.po.extpo.Page;
import com.xiguthings.waka.publicUtils.StringUtils;
import com.xiguthings.waka.service.user.IUserService;

@Service
@Transactional
public class UserServiceImpl implements IUserService{

	@Resource
	private UserMapper userMapper;
	
	@Override
	@Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
	public int insert(User record) throws Exception {
		String id = StringUtils.getRandomUUID();
		record.setUserId(id);
//		record.setCdBeginTime(new Date());
		record.setStatus(DataBaseStatus.NORMAL);
		return userMapper.insert(record);
	}

	@Override
	@Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
	public int updateByPrimaryKeySelective(User record) throws Exception {
		
		return userMapper.updateByPrimaryKeySelective(record);
	}

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED)
	public List<User> selectByExample(UserExample example) throws Exception {
		
		return userMapper.selectByExample(example);
	}

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED)
	public User selectByPrimaryKey(String userId) throws Exception {
		
		return userMapper.selectByPrimaryKey(userId);
	}


	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED)
	public User selectByOpenid(String openid) throws Exception {
		User user = null;
		UserExample example = new UserExample();
		example.createCriteria().andOpenidEqualTo(openid);
		List<User> list = userMapper.selectByExample(example);
		if (list != null && list.size() > 0) {
			user = list.get(0);
		}
		return user;
	}

	@Override
	public int countByExample(UserExample example) throws Exception {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int deleteByExample(UserExample example) throws Exception {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int deleteByPrimaryKey(String id) throws Exception {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int insertSelective(User t) throws Exception {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int updateByExampleSelective(User t, UserExample example) throws Exception {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int updateByExample(User t, UserExample example) throws Exception {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int updateByPrimaryKey(User t) throws Exception {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public Page selectByPage(Page pageEntity, UserExample example) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}
	
}
